home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-03 | 7.1 KB | 174 lines | [TEXT/CCL2] |
- ;;;
- ;;; cl.lisp
- ;;;
-
- #|
- ================================================================
- Purpose ========================================================
- ================================================================
- Defines a simple compile and load function. (OK not so simple any more!)
-
-
- ================================================================
- Status =========================================================
- ================================================================
- Released.
-
- Copyright © 1990-92 Chris Eliot. All Rights Reserved. Send
- bugs, comments, questions, and fixes to eliot@cs.umass.edu.
-
- ================================================================
- Change history =================================================
- ================================================================
- 3-Aug-92 mc Created this header, commented out cl form at bottom, and added
- the call to provide.
-
- |#
-
-
- (in-package "COMMON-LISP-USER")
-
-
- ;;; Default value of compile switch.
- (defvar *force-compile* nil)
-
- ;;; Default directory for binary files.
- (defvar *binary-file-directory* nil)
-
- ;;; Default list of files to check for assumed macros. It is assumed that
- ;;; all files depend upon macros in these files and must be recompiled if
- ;;; any file in this list is changed.
- (defvar *default-compile-after-files* nil)
-
- (defvar *binary-file-type* "FASL") ; Implementation dependent type for
- ; compiled files.
-
- ;;; Compile and load a file.
-
- ;;; file is the file to compile (if needed) and load. The file name should
- ;;;be specified without a type.
-
- ;;; compile-p forces a compile even if it is otherwise not thought to be
- ;;;needed (unless the source is missing.)
-
- ;;; load-p can have values, T, NIL or :IF-CHANGED. The default (T) forces
- ;;;the binary (if available) or source (if binary not available) to be
- ;;;loaded. NIL prevents loading entirely and is used to simple ensure that
- ;;;the file has been compiled. :IF-CHANGED causes the file to be loaded
- ;;;only if is needs to be recompiled. This is used when a system has
- ;;;already been loaded and only new changes need reloading.
-
- ;;; after is a list of files that are assumed to contain macros used by
- ;;;this source file. CL will ensure that this file is compiled after all
- ;;;files in the 'after' list.
-
- ;;; binary is the directory in which to put the binary file. Specify this
- ;;;argument if you want to keep the compiled versions of files in a
- ;;;different place from the source.
-
- ;;; This function can also be used for binary only files or files that
- ;;; should not be compiled, but specifying NIL for the compile-p argument.
-
- (defun cl (file &key
- (compile-p *force-compile*)
- (load-p t)
- (after *default-compile-after-files*)
- (binary *binary-file-directory*))
- (with-simple-restart
- (error "Skip CL ~s" file)
- ;; Merge pathnames to create the full pathnames for the source and
- ;; binary files. Use the (user-homedir-pathname) to first create a
- ;; base name and then merge in the correct types.
- (let* ((base-name (merge-pathnames file (user-homedir-pathname)))
- (binary-name (make-pathname
- :type *binary-file-type*
- :defaults (if binary
- (merge-pathnames binary base-name)
- base-name))
- )
- (source (make-pathname
- :type "LISP"
- :defaults base-name)))
- ;; We can't cope with the situation where neither a source or a
- ;; binary exist. Check for this and bomb.
- (when (and (null (probe-file source))
- (null (probe-file binary-name)))
- (error "No source or binary for ~s" file))
-
- ;; Analyze the arguments and file write dates to determine if a
- ;; compile is needed.
- (cond ((null (probe-file source))
- ;; No source found - Will warn about this when loading.
- (setq source nil)
- (setq compile-p nil))
- ((not (null compile-p)) #| Force compile |#)
- ((or (not (probe-file binary-name))
- (> (file-write-date source)
- (file-write-date binary-name)))
- ;; Source has changed - for new compile.
- (setq compile-p t))
-
- ;; Finally, check all of the dependency files for one with a
- ;; later compile date.
- ((loop for other-file in after
- for other-source =
- (make-pathname :type "LISP"
- :defaults
- (merge-pathnames other-file
- (user-homedir-pathname)))
- for other-binary =
- (make-pathname :type *binary-file-type*
- :defaults
- (merge-pathnames other-file (user-homedir-pathname)))
- ;; Check for a dependency file with a change or compile later
- ;; than the current file's compile date.
- thereis (or (and (probe-file other-binary)
- (> (file-write-date other-binary)
- (file-write-date binary-name)))
- (and (probe-file other-source)
- (> (file-write-date other-source)
- (file-write-date binary-name)))))
- (setq compile-p t))
- )
-
- ;; We have determined if a compile is needed; do it and determine if
- ;; loading is needed.
- (cond ((null compile-p)
- (when (eql load-p :if-changed)
- (setq load-p nil)))
- (t (format t "~&; Compiling ~s into ~s" source binary-name)
- ;; Note: Skip & Retry compiling are already available in CCL, so
- ;; this is not needed. Skip and retry Loading needs to be
- ;; implemented at this level.
- (with-simple-restart
- (error "Skip Compiling ~s" source)
- (let ((ok nil))
- ;; Loop until compile is successful or user aborts.
- (loop while (null ok)
- do (with-simple-restart
- (error "Retry Compiling ~s" source)
- (compile-file source :output-file binary-name)
- (setq ok t)))))))
- (when load-p
- (with-simple-restart
- (error "Skip Loading ~s" binary-name)
- (let ((ok nil))
- ;; Loop until load is successful or user aborts.
- (loop while (null ok)
- do (with-simple-restart
- (error "Retry Loading ~s" binary-name)
- (load binary-name)
- (if source
- (format t "~& From source ~s" source)
- (format t "*** No Source Available ***"))
- (setq ok t)))))
- )))
- )
-
-
- (provide "CL")
-
-
- #|
- (cl #p"HAT:AUX;cl" :after nil :load-p :if-changed :binary nil)
- |#